@{
ViewBag.Title = "商品首頁";
}
@section scripts
{
@Scripts.Render("~/bundles/jqueryval")
}
<h2>商品項目</h2>
<table>
@if (!Model.IdList.Count.Equals(0))
{
int row = Convert.ToInt32(Math.Ceiling(
Convert.ToDouble(Model.IdList.Count) / 5));
for (int r = 0; r < row; r++)
{
<tr>
@for (int i = 5 * r; i < (r + 1) * 5; i++)
{
if (i < Model.IdList.Count)
{
<td id="ItemBlock-@(Model.IdList[i])">
@Html.Partial("ItemBlock", Model.ItemBlock[i])
</td>
}
}
</tr>
}
}
else
{
<tr>
<td colspan="4">尚未有商品上架</td>
</tr>
}
<tr>
<td>
@if (Model.Paging.NowPage > 1)
{
@Html.ActionLink("<<", "Index", new { Page = 1 })
@Html.ActionLink("<", "Index"
, new { Page = Model.Paging.NowPage - 1 })
}
</td>
<td>
@for (var page = (Model.Paging.NowPage - 6);
page < (Model.Paging.NowPage + 6); page++)
{
if ((page > 0) && (page <= Model.Paging.MaxPage))
{
if (page == Model.Paging.NowPage)
{
<b>@page</b>
}
else
{
@Html.ActionLink(page.ToString(), "Index"
, new { Page = page })
}
}
}
</td>
<td>
@if (Model.Paging.NowPage < Model.Paging.MaxPage)
{
@Html.ActionLink(">", "Index"
, new { Page = Model.Paging.NowPage + 1 })
@Html.ActionLink(">>", "Index"
, new { Page = Model.Paging.MaxPage })
}
</td>
<td></td>
</tr>
</table>
@if (User.Identity.IsAuthenticated && User.IsInRole("Admin"))
{
<a href="@Url.Action("Create")">
<input type="button" value="新增商品" />
</a>
}
@{
ViewBag.Title = "商品資料-" + Model.Data.Name;
}
<h2>@Model.Data.Name</h2>
@Html.DisplayNameFor(model => model.Data.Price):
@Html.DisplayTextFor(model => model.Data.Price)<br />
<img src="@Html.Encode(Url.Content("~/Upload/" + Model.Data.Image))" />
<br />
@if (User.Identity.IsAuthenticated)
{
if (Model.InCart)
{
<text>已經於購物車中了,從購物車中</text>
@Html.ActionLink("取出", "Pop", "Cart"
, new { Id = Model.Data.Id, toPage = "Item" }, null)
}
else
{
@Html.ActionLink("放入購物車中", "Put", "Cart"
, new { Id = Model.Data.Id, toPage = "Item" }, null)
}
if (User.IsInRole("Admin"))
{
@Html.ActionLink("刪除商品", "Delete"
, new { Id = Model.Data.Id })
}
}
else
{
<text>要使用購物車請先</text>
@Html.ActionLink("登入", "Login", "Member")
}
<table>
<tr>
@*顯示商品圖片*@
<td>
<img width="100"
src="@Html.Encode(Url.Content("~/Upload/" + Model.Data.Image))" />
</td>
</tr>
<tr>
<td>
@Html.ActionLink(Model.Data.Name, "Item", new { Id = Model.Data.Id })
</td>
</tr>
<tr>
<td>
@if (User.Identity.IsAuthenticated)
{
if (Model.InCart)
{
<text>已經於購物車中了,從購物車中</text>
@Ajax.ActionLink("取出", "Pop", "Cart"
, new { Id = Model.Data.Id, toPage = "ItemBlock" }
, new AjaxOptions
{
InsertionMode = InsertionMode.Replace
,
UpdateTargetId = "ItemBlock-" + Model.Data.Id
})
}
else
{
@Ajax.ActionLink("放入購物車中", "Put", "Cart"
, new { Id = Model.Data.Id, toPage = "ItemBlock" }
, new AjaxOptions
{
InsertionMode = InsertionMode.Replace
,
UpdateTargetId = "ItemBlock-" + Model.Data.Id
})
}
}
else
{
<text>要使用購物車請先</text>
@Html.ActionLink("登入", "Login", "Member")
}
</td>
</tr>
</table>
@{
ViewBag.Title = "新增商品";
}
@section scripts
{
@Scripts.Render("~/bundles/jqueryval")
}
<h2>新增商品</h2>
@using (Html.BeginForm("Add", "Home", FormMethod.Post
, new { enctype = "multipart/form-data" }))
{
@Html.ValidationSummary(true)
<table>
<tr>
<td>
@Html.LabelFor(model => model.NewData.Name)
</td>
<td>
@Html.TextBoxFor(model => model.NewData.Name)
@Html.ValidationMessageFor(model => model.NewData.Name)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.NewData.Price)
</td>
<td>
@Html.TextBoxFor(model => model.NewData.Price)
@Html.ValidationMessageFor(model => model.NewData.Price)
</td>
</tr>
<tr>
<td>
@Html.LabelFor(model => model.ItemImage)
</td>
<td>
@*<input type="file" name="ItemImage" id="ItemImage" />*@
@Html.TextBoxFor(model => model.ItemImage, new { type = "file" })
@Html.ValidationMessageFor(model => model.ItemImage)
</td>
</tr>
</table>
<input type="submit" value="商品上架" />
歷經了三十天對.NET MVC又進一步的認識,目前使用.NET MVC的時間大約是四個月,算是一個菜鳥工程師,所以在編寫上可能有點差強人意,但繼續努力總是能完成目標!